package com.yxw.live_vod_boot.controller;

import com.yxw.live_vod_boot.dto.PageUserListDto;
import com.yxw.live_vod_boot.dto.UpdateUserDTO;
import com.yxw.live_vod_boot.dto.UpdateUserPayPwdDTO;
import com.yxw.live_vod_boot.service.UserService;
import com.yxw.live_vod_boot.vo.UserInfoVo;
import com.yxw.yxnet_cd_center.common.dto.PageVO;
import com.yxw.yxnet_cd_center.common.utils.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 平台人员管理
 * @author liuxin
 * @date 2023.12.1
 */
@RestController
@Api(value = "平台人员管理", tags = "平台人员管理")
@Slf4j
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping(value = "/updateHeaderImage")
    @ApiOperation(value = "人员头像修改")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "headImage", value = "人员头像", required = true, dataType = "Long",  paramType = "query")
//    })
    public BaseResult updateHeaderImage(@RequestParam(name = "headImage") MultipartFile headImage,
                                        @RequestParam(name = "userId") Long userId){
        userService.updateHeaderImage(headImage,userId);
        return BaseResult.doSuccess(null,"头像修改成功");
    }

    @PostMapping(value = "/updateUserById")
    @ApiOperation(value = "人员信息修改")
    public BaseResult updateUserById(@RequestBody @Valid UpdateUserDTO dto){
        userService.updateUserById(dto);
        return BaseResult.doSuccess(null,"修改成功");
    }

    @PostMapping(value = "/updatePayPwdByPhone")
    @ApiOperation(value = "修改支付密码")
    public BaseResult updatePayPwdByPhone(@RequestBody @Valid UpdateUserPayPwdDTO dto){
        userService.updatePayPwdByPhone(dto);
        return BaseResult.doSuccess(null,"修改成功");
    }

    @PostMapping(value = "/logAffAccount")
    @ApiOperation(value = "注销账户")
    public BaseResult logAffAccount(@RequestParam @Valid @NotNull(message = "账号ID不能为空") Long userId){
        userService.logAffAccount(userId);
        return BaseResult.doSuccess(null,"注销成功");
    }

    @PostMapping(value = "/pageUserList")
    @ApiOperation(value = "人员查询公用组件")
    public BaseResult<PageVO<UserInfoVo>> pageUserList(@RequestBody PageUserListDto dto){
        PageVO<UserInfoVo> pageVo=userService.pageUserList(dto);
        return BaseResult.doSuccess(pageVo,"查询成功");
    }

    @PostMapping(value = "/getUserList")
    @ApiOperation(value = "获取人员列表")
    public BaseResult<List<UserInfoVo>> getUserList(){
        List<UserInfoVo> voList=userService.getUserList();
        return BaseResult.doSuccess(voList,"查询成功");
    }

    @PostMapping(value = "/getUserInfo")
    @ApiOperation(value = "获取用户信息详情")
    public BaseResult getUserInfo(@RequestParam("userId") Long userId){
        UserInfoVo vo = userService.getUserInfo(userId);
        return BaseResult.doSuccess(vo,"查询成功");
    }
}
